package com.cropflow.repository;

import com.cropflow.entity.Vehicle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface VehicleRepository extends JpaRepository<Vehicle, Long> {
    
    List<Vehicle> findByStatus(Vehicle.VehicleStatus status);
    
    List<Vehicle> findByType(String type);
    
    @Query("SELECT v FROM Vehicle v WHERE v.batteryLevel < :threshold")
    List<Vehicle> findLowBatteryVehicles(Double threshold);
    
    @Query("SELECT v FROM Vehicle v WHERE v.status = 'ERROR'")
    List<Vehicle> findErrorVehicles();
    
    List<Vehicle> findByNameContaining(String name);
    
    // 添加方法
    List<Vehicle> findVehiclesNeedingMaintenance(LocalDateTime date);
}